import request from '@/utils/request'

// 时间同步
export function syncDeviceTime(deviceId, timeConfig) {
  return request({
    url: `/devices/${deviceId}/time/sync`,
    method: 'post',
    data: timeConfig
  })
}

// 获取设备时间
export function getDeviceTime(deviceId) {
  return request({
    url: `/devices/${deviceId}/time`,
    method: 'get'
  })
}

// 设置设备时间
export function setDeviceTime(deviceId, timeConfig) {
  return request({
    url: `/devices/${deviceId}/time`,
    method: 'put',
    data: timeConfig
  })
}

// 获取网络配置
export function getNetworkConfig(deviceId) {
  return request({
    url: `/devices/${deviceId}/network`,
    method: 'get'
  })
}

// 设置网络配置
export function setNetworkConfig(deviceId, networkConfig) {
  return request({
    url: `/devices/${deviceId}/network`,
    method: 'put',
    data: networkConfig
  })
}

// 重启设备
export function rebootDevice(deviceId) {
  return request({
    url: `/devices/${deviceId}/reboot`,
    method: 'post'
  })
}

// 恢复出厂设置
export function factoryReset(deviceId) {
  return request({
    url: `/devices/${deviceId}/factory-reset`,
    method: 'post'
  })
}

// 导出设备配置
export function exportDeviceConfig(deviceId) {
  return request({
    url: `/devices/${deviceId}/config/export`,
    method: 'get',
    responseType: 'blob'
  })
}

// 导入设备配置
export function importDeviceConfig(deviceId, configFile) {
  const formData = new FormData()
  formData.append('config', configFile)
  return request({
    url: `/devices/${deviceId}/config/import`,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取设备能力集
export function getDeviceCapabilities(deviceId) {
  return request({
    url: `/devices/${deviceId}/capabilities`,
    method: 'get'
  })
}

// 获取设备性能指标
export function getDeviceMetrics(deviceId, params) {
  return request({
    url: `/devices/${deviceId}/metrics`,
    method: 'get',
    params
  })
}

// 获取设备状态
export function getDeviceStatus(deviceId) {
  return request({
    url: `/devices/${deviceId}/status`,
    method: 'get'
  })
}

// 获取设备信息
export function getDeviceInfo(deviceId) {
  return request({
    url: `/devices/${deviceId}/info`,
    method: 'get'
  })
}

// 获取设备日志
export function getDeviceLogs(deviceId, params) {
  return request({
    url: `/devices/${deviceId}/logs`,
    method: 'get',
    params
  })
}

// 清除设备日志
export function clearDeviceLogs(deviceId) {
  return request({
    url: `/devices/${deviceId}/logs`,
    method: 'delete'
  })
}

// 获取设备存储信息
export function getDeviceStorage(deviceId) {
  return request({
    url: `/devices/${deviceId}/storage`,
    method: 'get'
  })
}

// 格式化存储
export function formatStorage(deviceId, storageId) {
  return request({
    url: `/devices/${deviceId}/storage/${storageId}/format`,
    method: 'post'
  })
}

// 获取设备用户列表
export function getDeviceUsers(deviceId) {
  return request({
    url: `/devices/${deviceId}/users`,
    method: 'get'
  })
}

// 添加设备用户
export function addDeviceUser(deviceId, userConfig) {
  return request({
    url: `/devices/${deviceId}/users`,
    method: 'post',
    data: userConfig
  })
}

// 删除设备用户
export function deleteDeviceUser(deviceId, username) {
  return request({
    url: `/devices/${deviceId}/users/${username}`,
    method: 'delete'
  })
}

// 修改设备用户
export function updateDeviceUser(deviceId, username, userConfig) {
  return request({
    url: `/devices/${deviceId}/users/${username}`,
    method: 'put',
    data: userConfig
  })
}